package com.leader.kotlinmvp.rx.scheduler

import io.reactivex.*
import org.reactivestreams.Publisher

/**
 *
 * <p>
 * 类的描述: RxJava2.x 5中基础相应类型
 * 创建时间: 2019/5/8 9:22
 * 修改备注:
 */

abstract class BaseScheduler<T> protected constructor(
        private val subscribeOnScheduler: Scheduler,
        private val observeOnSubscribe: Scheduler) :
        ObservableTransformer<T, T>,
        SingleTransformer<T, T>,
        MaybeTransformer<T, T>,
        CompletableTransformer,
        FlowableTransformer<T, T> {

    override fun apply(upstream: Completable): CompletableSource {
        return upstream.subscribeOn(subscribeOnScheduler)
                .observeOn(observeOnSubscribe)
    }

    override fun apply(upstream: Flowable<T>): Publisher<T> {
        return upstream.subscribeOn(subscribeOnScheduler)
                .observeOn(observeOnSubscribe)
    }

    override fun apply(upstream: Maybe<T>): MaybeSource<T> {
        return upstream.subscribeOn(subscribeOnScheduler)
                .observeOn(observeOnSubscribe)
    }

    override fun apply(upstream: Observable<T>): ObservableSource<T> {
        return upstream.subscribeOn(subscribeOnScheduler)
                .observeOn(observeOnSubscribe)
    }

    override fun apply(upstream: Single<T>): SingleSource<T> {
        return upstream.subscribeOn(subscribeOnScheduler)
                .observeOn(observeOnSubscribe)
    }
}